<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="app">
    <button @click="isShow = !isShow">切换组件状态</button>
    <common-head v-if="isShow"></common-head>
  </div>
  <script src="./vue.global.js"></script>
  <script>
    const { createApp } = Vue;
    const app = createApp({
      data() {
        return {
          isShow: true
        }
      }
    });
    const CommonHead = {
      template: `
        <div>
          <h2>这是组件1</h2>
          <button ref="btn" @click="addArr">按钮</button>
          <ul ref="oul">
            <li v-for="item in arr" :key="item">
              {{item}}  
            </li>  
          </ul>
        </div>
      `,
      data() {
        return {
          arr: [1,2,3,4]
        }
      },
      methods: {
        addArr() {
          this.arr.push(this.arr.length+1)
        }
      },
      beforeCreate() {
        console.log('实例还未完成， beforeCreate');
      
      },
      created() {
        console.log('实例创建完成， created');
        // this.fn();
        console.log(this.$refs.btn);
      },
      beforeMount() {
        console.log('dom还未渲染 beforeMount');
        console.log(this.$refs.btn);
      },
      mounted() {
        console.log('dom渲染完成 mounted');
        console.log(this.$refs.btn);
      },
      beforeUpdate() {
        console.log('beforeUpdate');
        console.log(this.$refs.oul.children);
      },
      updated() {
        console.log('updated');
        console.log(this.$refs.oul.children);
      },
      beforeUnmount() {
        console.log('beforeUnmount 卸载之前');
      },
      unmounted() {
        console.log('unmounted 卸载了');
      },
    }
    app.component('CommonHead', CommonHead)


    app.mount('#app')
  </script>
</body>

</html>